package com.tj.exceldemo.excel_demo.controller;

import com.tj.exceldemo.excel_demo.service.FileImportService;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class FileImportController {

    @Resource
    private FileImportService fileImportService;

    @PostMapping("/upload")
    @ResponseBody
    public String upload(@RequestParam("file") MultipartFile file) throws IOException {
        if (!file.isEmpty()) {
            fileImportService.importFileAsync(file);
        }
        return "import success!";
    }

    @GetMapping("/")
    public String index() {
        return "index";
    }
}
